package edu.ccut.saturn.studio.wfg.part;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;

import edu.ccut.saturn.studio.wfg.model.Connection;
import edu.ccut.saturn.studio.wfg.model.Shape;
import edu.ccut.saturn.studio.wfg.model.ShapesDiagram;

public class ShapesEditPartFactory implements EditPartFactory {

	private static final String SHAPES_EDIT_PART_FACTORY_NULL1 = "null";
	private static final String SHAPES_EDIT_PART_FACTORY_ERROR = "Can't create part for model element: ";

	public EditPart createEditPart(EditPart context, Object modelElement) {
		EditPart part = getPartForElement(modelElement);
		part.setModel(modelElement);
		return part;
	}

	private EditPart getPartForElement(Object modelElement) {
		if (modelElement instanceof ShapesDiagram) {
			return new DiagramEditPart();
		}
		if (modelElement instanceof Shape) {
			return new ShapeEditPart();
		}
		if (modelElement instanceof Connection) {
			return new ConnectionEditPart();
		}
		throw new RuntimeException(SHAPES_EDIT_PART_FACTORY_ERROR
				+ ((modelElement != null) ? modelElement.getClass().getName()
						: SHAPES_EDIT_PART_FACTORY_NULL1));
	}
}